package foo.bar.wiki.web.action.space;

import foo.bar.wiki.web.action.BaseActionBean;
import foo.bar.wiki.web.action.general.DashboardActionBean;
import foo.bar.wiki.web.extension.SpaceTypeConverter;
import foo.bar.wiki.domain.Space;
import foo.bar.wiki.services.WikiService;
import foo.bar.wiki.plugins.PluginException;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.SimpleMessage;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.integration.spring.SpringBean;

/**
 * @author tmjee
 * @version $Date$ $Id$
 */
public class RemoveSpaceActionBean extends BaseActionBean {

    @Validate(converter = SpaceTypeConverter.class)
    private Space space;

    private WikiService wikiService;


    public Resolution remove() throws PluginException {
        wikiService.removeSpace(space);
        getContext().getMessages().add(new SimpleMessage("Space ["+space.getName()+"] deleted successfully"));
        return new RedirectResolution(DashboardActionBean.class, "view");
    }


    @SpringBean("wikiService")
    public void setWikiService(WikiService wikiService) {
        this.wikiService = wikiService;
    }

    public Space getSpace() {
        return space;
    }

    public void setSpace(Space space) {
        this.space = space;
    }
}
